﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Biblioteca.fachada;
using Biblioteca.classesBasicas.equipamento;


namespace Desktop.views.cruds.crudsEquipamento.crudCapacete
{
    public partial class MenuCapacete : Form
    {
        private MenuEquipamento menuEquipamento;
        private Fachada fachada = new Fachada();
        private List<Capacete> listaCapacetes;
        private Capacete capacete = new Capacete();
                

        public MenuCapacete(MenuEquipamento menuEquipamento)
        {
            this.menuEquipamento = menuEquipamento;
            menuEquipamento.Hide();

            InitializeComponent();
        }

        private void buttonCadastrar_Click(object sender, EventArgs e)
        {
            CadastroCapacete cadastroCapacete = new CadastroCapacete(this);
            cadastroCapacete.ShowDialog();
        }

        private void buttonSair_Click(object sender, EventArgs e)
        {
            menuEquipamento.Show();
            this.Dispose();
        }

        private void MenuCapacete_FormClosed(object sender, FormClosedEventArgs e)
        {
            menuEquipamento.Show();
            this.Dispose();
        }

        private void MenuCapacete_Load(object sender, EventArgs e)
        {
            carregarGridViewCapacete();
        }


        private void dataGridViewCapacete_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                DataGridViewRow row = this.dataGridViewCapacete.Rows[e.RowIndex];

                capacete.Id = row.Cells[0].Value.ToString();
                capacete.Nome = row.Cells[1].Value.ToString();
                capacete.Tipo = row.Cells[2].Value.ToString();
                capacete.Marca = row.Cells[3].Value.ToString();
                capacete.Valor = row.Cells[4].Value.ToString();

                AlterarRemoverCapacete alterar = new AlterarRemoverCapacete(this, capacete);
                alterar.ShowDialog();
            }
        }


        public void carregarGridViewCapacete()
        {
            listaCapacetes = fachada.listarCapacete();

            DataGridViewCellStyle columnHeaderStyle =
            new DataGridViewCellStyle();
            columnHeaderStyle.BackColor = Color.Aqua;
            columnHeaderStyle.Font =
                new Font("Verdana", 10, FontStyle.Bold);
            this.dataGridViewCapacete.ColumnHeadersDefaultCellStyle =
                columnHeaderStyle;

            dataGridViewCapacete.DataSource = listaCapacetes;

            this.dataGridViewCapacete.Columns[0].HeaderText = "ID";
            this.dataGridViewCapacete.Columns[1].HeaderText = "NOME";
            this.dataGridViewCapacete.Columns[2].HeaderText = "TIPO";
            this.dataGridViewCapacete.Columns[3].HeaderText = "MARCA";
            this.dataGridViewCapacete.Columns[4].HeaderText = "VALOR";
        }
        
    }
}
